﻿using System;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using OakEngine.AI;

namespace MainJumpFleet.TempObjects
{
    public class Turret
    {
        Texture2D turretTexture;

       public Vector2 m_vecTurrentPosition;

        Vector2 m_vecTargetPosition;

        Vector2 m_vecOrigin;

        float m_fRotationRate;

        float m_fCurrentRotation;

        public Rectangle Bounds;

        public bool m_bisAlive;


        public Turret(Texture2D texture)
        {
            turretTexture = texture;
            m_vecOrigin = new Vector2(turretTexture.Width * 0.5f, texture.Height * 0.5f);
            Bounds = new Rectangle();
            m_bisAlive = true;
        }

        public void SetTarget(Vector2 target)
        {
            m_vecTargetPosition = target;
        }

        public void SetPos(Vector2 p)
        {
            m_vecTurrentPosition = p;
            Bounds = new Rectangle((int)p.X, (int)p.Y, turretTexture.Width, turretTexture.Height);
        }

        

        public void SetRotation(float x)
        {
            m_fCurrentRotation += x;
        }

        public float Rot { get {return m_fCurrentRotation; } }

        public void Update()
        {
            m_fCurrentRotation = OakEngine.AI.Tools.OAK_AITools.TurnToAim(m_vecTurrentPosition, m_vecTargetPosition, m_fCurrentRotation);
                   
            
        }

        public void Render(SpriteBatch batch)
        {
            if(m_bisAlive)
            batch.Draw(turretTexture, m_vecTurrentPosition, null, Color.White, m_fCurrentRotation + 1.5f, m_vecOrigin, 1, SpriteEffects.None, 0);
        }
    }
}
